﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：DataAccessReprot
// 文件功能描述：报表数据层 负责读取报表数据
//
// 
// 创建标识：2012-01-03 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace DAO.WaiGaoQiao
{
    public class DataAccessReprot
    {
        /// <summary>
        /// 原材料验收单
        /// </summary>
        /// <returns></returns>
        public DataSet GetMaterialInspection(string dt, int gid, int pagesize, int startindex)
        {
            sqldb db = new sqldb();
            int startrow = pagesize * (startindex - 1);
            int endrow = pagesize * startindex + 1;
            string query = "SELECT rownumber,B.ID,B.InstockDt,B.Warehouse_ID,B.Group_ID,"
                        + "B.Goods_ID,B.Count,B.Price,B.Amount,E.Supplier_Name,B.RecordDateTime,B.OperatorID,B.OrderNo "
                        + "FROM (select ROW_NUMBER() OVER(ORDER BY A.ID DESC) rownumber,ID,InstockDt,Warehouse_ID,Group_ID,"
                        + "Goods_ID,Count,Price,Amount,Supplier_ID,RecordDateTime,OperatorID,OrderNo "
                        + "from Con_Instock_Detailed A Where InstockDt = '" + dt
                        + "'";
            if (gid != -1)
            {
                query += "and Warehouse_ID = " + gid.ToString();
            }
            query += ") B left JOIN con_supplier E ON B.Supplier_ID=E.ID "
                        + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
            DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
            return ds;
        }

        public int GetMaterialInspectionCount(string dt, int gid)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Con_Instock_Detailed where InstockDt = '"
                    + dt + "'";
            if (gid != -1)
            {
                query += "and Warehouse_ID =" + gid.ToString();
            }
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }
        /// <summary>
        /// 二食堂荤菜、蔬菜、鱼
        /// </summary>
        /// <param name="yy"></param>
        /// <param name="mm"></param>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public DataSet GetCanteenNonstapleFood(int yy, int mm, int shtang, int pagesize, int startindex)
        {
            sqldb db = new sqldb();
            int startrow = pagesize * (startindex - 1);
            int endrow = pagesize * startindex + 1;
            string query = "Execute Proc_CanteenNonstapleFood " + yy.ToString() + ","
                        + mm.ToString() + "," + shtang.ToString() + "," + startrow.ToString() + "," + endrow.ToString();
            DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
            return ds;
        }
        public int GetCanteenNonstapleFoodCount(int yy, int mm, int shtang)
        {
            sqldb db = new sqldb();
            string query = "Execute Proc_CanteenNonstapleFood " + yy.ToString() + ","
                + mm.ToString() + "," + shtang.ToString() + ",0,40";
            DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
            return ds.Tables[0].Rows.Count;
        }

        public DataSet GetCostAccount(int gid, string dt)
        {
            sqldb db = new sqldb();
            string query = "Execute Proc_CostAccountingForGroup '" + dt + "'," + gid.ToString();
            DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
            return ds;
        }
        /// <summary>
        /// 餐饮部原料统计表-第一食堂
        /// </summary>
        /// <param name="yy"></param>
        /// <param name="mm"></param>
        /// <param name="st"></param>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public DataSet GetProc_RawMaterialsAndStatistics(int yy, int mm, int st, int pagesize, int startindex)
        {
            sqldb db = new sqldb();
            int startrow = pagesize * (startindex - 1);
            int endrow = pagesize * startindex + 1;
            string query = "Execute Proc_RawMaterialsAndStatistics '" + yy.ToString() + "'," + mm.ToString()
                + "," + st.ToString() + "," + startrow.ToString() + "," + endrow.ToString();
            DataSet ds = db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
            return ds;
        }
        /// <summary>
        /// 餐饮部原料统计表-第一食堂 数量
        /// </summary>
        /// <param name="yy"></param>
        /// <param name="mm"></param>
        /// <param name="st"></param>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public int GetProc_RawMaterialsAndStatisticsCount(int yy, int mm, int st)
        {
            sqldb db = new sqldb();
            string query = "Execute Proc_RawMaterialsAndStatisticsCount '" + yy.ToString() + "'," + mm.ToString()
                + "," + st.ToString();
            object rowint = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowint);
        }
    }
}
